package smb;

import static org.junit.Assert.assertTrue;

import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IDebugProperty;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that PwnU2 moves to all four corners per its specified strategy. Note:
 * Professor Johnson code.
 * 
 * @author Prof. Johnson
 * 
 */
public class TestPwnUCornerMovement extends RobotTestBed {
 /** True if the robot visited this corner during the test case. */
 boolean visitedUpperLeft = false;
 /** True if the robot visited this corner during the test case. */
 boolean visitedUpperRight = false;
 /** True if the robot visited this corner during the test case. */
 boolean visitedLowerLeft = false;
 /** True if the robot visited this corner during the test case. */
 boolean visitedLowerRight = false;
 /** True if robot rams another robot. */
 boolean ramRobot = false;

 /**
  * Specifies that Crazy and PwnU2 are to be matched up in this test case. PwnU2
  * will stop and fire at sitting duck, needed to match up against a moving
  * robot so that PwnU2 will have to move.
  * 
  * @return The comma-delimited list of robots in this match.
  */
 @Override
 public String getRobotNames() {
  return "sample.Crazy,smb.PwnU2";
 }

 /**
  * This test runs for 1 round.
  * 
  * @return The number of rounds.
  */
 @Override
 public int getNumRounds() {
  return 10;
 }

 /**
  * After each turn, check to see if we're at a corner. If so, set the
  * corresponding flag.
  * 
  * @param event
  *         Info about the current state of the battle.
  */
 @Override
 public void onTurnEnded(TurnEndedEvent event) {
  IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
  double xPos = robot.getX();
  double yPos = robot.getY();
  // Checks to see if the robot visited the top left corner
  if ((xPos < 40) && (yPos < 40)) {
   visitedUpperLeft = true;
  }
  if ((xPos < 40 && (yPos > (height - 40)))) {
   visitedLowerLeft = true;
  }
  if ((xPos > (width - 40)) && (yPos < 40)) {
   visitedUpperRight = true;
  }
  if ((xPos > (width - 40) && (yPos > (height - 40)))) {
   visitedLowerRight = true;
  }

  for (IDebugProperty buggy : robot.getDebugProperties()) {
   if (buggy.getKey().compareToIgnoreCase("onHit") == 0
     && (buggy.getValue().compareToIgnoreCase("true") == 0)) {
    ramRobot = true;
   }

  }
 }

 /**
  * After the battle, check to see that we've visited the corners.
  * 
  * @param event
  *         Details about the completed battle.
  */
 @Override
 public void onBattleCompleted(BattleCompletedEvent event) {
  assertTrue("Check UpperLeft", visitedUpperLeft);
  assertTrue("Check LowerLeft", visitedLowerLeft);
  assertTrue("Check UpperRight", visitedUpperRight);
  assertTrue("Check LowerRight", visitedLowerRight);
  assertTrue("Check if Ram robot", ramRobot);
  // assertTrue("Check if visited Center", center);

 }

}
